package com.finstone.data.spider.eshop.processor;

import org.springframework.stereotype.Component;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

@Component
public class EShopGoodsDetailImageProcessor implements PageProcessor {

	private Site site = Site.me().setCycleRetryTimes(3).setTimeOut(30000);

	public Site getSite() {
		site.addHeader("Referer", "http://www.lenovo.com.cn/");
		site.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36");
		return site;
	}

	public void process(Page page) {
		String url = page.getRequest().getUrl();
		page.putField("url", url);
		page.putField("id", page.getRequest().getExtra("id"));
		page.putField("dir_id", page.getRequest().getExtra("dir_id"));
		page.putField("real_id",page.getRequest().getExtra("real_id"));
		page.putField("suffix", url.substring(url.lastIndexOf(".")));
		page.putField("imageBinStr", page.getRawText());
	}
}
